<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :cities="cities" :hotCities="hotCities" :letter="letter"></city-list>
    <city-alphabet :cities="cities" @change="handleLetterChange"></city-alphabet>
  </div>
</template>

<script>
import axios from 'axios'
import CityHeader from '@/components/cityComponents/CityHeader'
import CitySearch from '@/components/cityComponents/CitySearch'
import CityList from '@/components/cityComponents/CityList'
import CityAlphabet from '@/components/cityComponents/CityAlphabet'
export default {
  name: 'City',
  data() {
    return {
      cities: {},
      hotCities: [],
      letter: ''
    }
  },
  components: {
    CityHeader,
    CitySearch,
    CityList,
    CityAlphabet
  },
  mounted() {
    // console.log('City-mounted')
    this.getCityInfo()
  },
  activated() {
    // console.log('City-actived')
  },
  methods: {
    // 获取数据
    getCityInfo() {
      axios.get('/api/city.json').then(res => {
        res = res.data
        if (res.ret && res.data) {
          this.cities = res.data.cities
          this.hotCities = res.data.hotCities
        }
      })
    },
    // 监听CityAlphabbet组件的点击事件，参数为点击的当前字母
    handleLetterChange(letter) {
      this.letter = letter
    }
  }
}
</script>

<style scoped lang="stylus"></style>
